package com.rd.student.jike.class2.lihongming.Solutions5;

import java.io.*;

/**
 * @Auther:Heinrich
 * @Date:2023/7/31-07-31-10:39
 * @Description:com.rd.student.jike.class2.lihongming.Solutions5
 * @version:1.0
 */
public class Question3 {
    public static void main(String[] args) throws IOException {
        File file = new File("..\\rd2304\\src\\com\\rd\\student\\jike\\class2\\lihongming/Solution5_1");
        file.mkdir();
        CopyAll(new File("..\\rd2304\\src\\com\\rd\\student\\jike\\class2\\lihongming\\Solutions5"),file);
    }
    public static void copyPaper(File fileSource , File fileDestination) throws IOException {
        FileInputStream is = new FileInputStream(fileSource);
        if(!fileDestination.exists()){
            fileDestination.createNewFile();
        }
        FileOutputStream os = new FileOutputStream(fileDestination,true);
        byte[] pipe = new byte[1024];
        int len = 0;
        while ((len = is.read(pipe)) != -1){
            os.write(pipe,0,len);
        }
        is.close();
        os.close();
    }
    public static void CopyAll(File fileS,File fileD) throws IOException {
        File[] files = fileS.listFiles();
        if (files == null || files.length == 0) return;
        for (File tmpFile : files) {
            System.out.println(fileS.getName()+" : "+tmpFile.getName());
            if (tmpFile.isDirectory()) {
                File tmFile1 = new File(fileD+"/"+tmpFile.getName());
                tmFile1.mkdir();
                CopyAll(tmpFile,tmFile1);
            }else{
                File tmFile1 = new File(fileD+"/"+tmpFile.getName());
                System.out.println(tmFile1);
                if(!tmFile1.exists()){
                    tmFile1.createNewFile();
                }
                copyPaper(tmpFile,tmFile1);
            }
        }
    }
}
